﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Blueprint.Domain
{
    public partial class NorthwindDataContext
    {
        public Category[] GetCategories()
        {
            // All Categories (without any childs)
            //return Categories.ToArray();

            // All Categories (with Products loaded for first)
            var q = from c in Categories select c;
            Category[] categories = q.ToArray();
            foreach(Category category in categories)
                category.Products.Load();

            // All Categories (with Products loaded)
            //DataLoadOptions dlo = new DataLoadOptions();
            //dlo.LoadWith<Category>(c => c.Products);
            //LoadOptions = dlo; 
            //var q = from c in Categories select c;
            //Category[] cats = q.ToArray();

            return categories;
        }

        public Category GetCategory(int categoryID)
        {
            Category category = Categories.SingleOrDefault<Category>(c => c.CategoryID == categoryID);
            category.Products.Load();
            return category;
        }
    }
}
